from sys import argv


class ModuleNode(object):

    def __init__(self, name):
        self.__name = name
        self.__childModules = set([])
        self.__parentModules = set([])

    def add_child(self, mchild):
        self.__childModules.add(mchild)

    def add_parent(self, mparent):
        self.__parentModules.add(mparent)

    def get_children(self):
        return self.__childModules

    def get_parents(self):
        return self.__parentModules

reached = []
moduleTree = {}


def print_parent(modulename, j):
    if modulename in reached:
        print('\t' * j + '|-found loop')
        return
    reached.append(modulename)
    print('\t' * j + '|-'+modulename)
    for parent in moduleTree[modulename].get_parents():
        print_parent(parent, j+1)
    reached.remove(modulename)

filename = argv
myFile = open(filename[1], 'r')
lines = myFile.readlines()
myFile.close()
index = -1

for i in range(len(lines)):
    if not lines[i].startswith('[100% 1/1]'):
        continue
    else:
        index = i
        break

tempLines = lines[index].split(' ')
lines[index] = tempLines[-1]
lastModule = ''
ignore = False

for i in range(index, len(lines)):
    if not lines[i].startswith(' '):
        lastModule = lines[i].strip('\n')
        if 'test' in lastModule.lower():
            ignore = True
            continue
        ignore = False
        if lastModule not in moduleTree:
            moduleTree[lastModule] = ModuleNode(lastModule)
    else:
        if ignore:
            continue
        childModule = lines[i].lstrip().strip('\n')
        if childModule not in moduleTree:
            moduleTree[childModule] = ModuleNode(childModule)
        moduleTree[lastModule].add_child(childModule)

for key in moduleTree.keys():
    currentModule = moduleTree[key]
    for child in currentModule.get_children():
        moduleTree[child].add_parent(key)

# lastModule = raw_input('please input modulename : ')
lastModule =  argv[2]
if lastModule in moduleTree:
    print_parent(lastModule, 0)
else:
    print('module name is wrong.')
# while lastModule != "exit":
    # if lastModule in moduleTree:
    #     print_parent(lastModule, 0)
    # else:
    #     print('module name is wrong.')
#     lastModule = raw_input('please input modulename : ')
